<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Rss/classes/PhpFox_ComponentRssCreate.class.php, $Author:  $ */


/** Component for RSS (1.0 & 2.0) creation.
 * @package module.Rss
 * @version $Id: PhpFox_ComponentRssCreate.class.php 439 2008-04-18 18:59:41Z phpfoxsv $
 */
class PhpFox_Mod_Rss_ComponentRssCreate extends BaseComponent{

    function process(){
        $oRssService = &$this->_oModule->getService('Rss');
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */

        $oReq = &App::getRequest();
        $sRssFeedType = $oReq->get('act');
        $sRssType     = $oReq->get('rss');
        $sRssType     = ('10' == $sRssType) ? '10' : '20';

        if(!in_array($sRssFeedType,array('blogs','threads','events', 'posts'))){
            return '<?xml version="1.0"?>';
        }

        $aRssData = array();
        switch($sRssFeedType) {
            case 'blogs':
                if ($oSecurityService->checkPerm('blog', array('read_only', 'full'), false))
                {
                	$oReq = &App::getRequest();
                	$iUserId = ($oReq->getInt('userid') ? $oReq->getInt('userid') : '');
                    $aRssData  = $oRssService->getBlogsArray($iUserId);
                }
                break;
            case 'threads':
                if ($oSecurityService->checkPerm('forum', array('read_only', 'full'), false))
                {
                    $iThreadId = $oReq->getInt('id');
                    if ( App::pluginInstalled('vbulletin') )
                    {
						$aRssData = vbulletin_rss_feed($iThreadId);
						foreach ($aRssData as $iKey => $aData)
						{
							$aRssData[$iKey]['description'] = $oRssService->unhtmlentities($aRssData[$iKey]['description']);
						}						
                    }
                    else
                    {
                    	$aRssData  = $oRssService->getThreadsArray($iThreadId);
                    }
                }
                break;
            case 'events':
                if ($oSecurityService->checkPerm('events', array('read_only', 'full'), false))
                {
                    $aRssData  = $oRssService->getEventsArray();
                }
                break;
            case 'posts':
                if ($oSecurityService->checkPerm('forum', array('read_only', 'full'), false))
                {
                    $iPostId   = $oReq->getInt('id');
                    $aRssData  = $oRssService->getPostsArray($iPostId);
                }
                break;
        }

         App::loadClass('rss/rss10');

        $oRss = new RSS();
        if (isset($aRssData['rss_link']))
        {
        	$sLink = $aRssData['rss_link'];
        	unset($aRssData['rss_link']);
        }
        if (isset($aRssData['rss_title']) && $aRssData['rss_title'])
        {
            $sTitle = App::getParam('site_title') . " :: " . $aRssData['rss_title'];
            unset($aRssData['rss_title']);
        }
        else
        {
            $sTitle = App::getParam('Mod_Rss.'.$sRssFeedType.'_title');
        }
        $sDescription = App::getParam('Mod_Rss.'.$sRssFeedType.'_description');
        
        $sLink = (isset($sLink) ? $sLink : App::getParam('url'));

        $oLang =& App::getLanguage();
        $aLang = $oLang->getDetails();
		$oRss->charset = $aLang['charset'];

		$sAbout = App::getParam('http').App::getParam('host');
		$oRss->setChannel($sTitle, $sDescription, $sLink, $sAbout);

        $oRss->addData($aRssData);

        return $oRss->get();

    }
}
?>